<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let loginList = [
            { userName: 'admin', password: 'admin321' },
            { userName: 'zhangsan', password: 'zs321' },
            { userName: 'lisi', password: 'ls321' },
            { userName: 'yyqx', password: 'yyqx321' }
        ]
        let userInfo = {
            token1: {
                city: '杭州',
                money: '1000w',
                sex: '女',
                userName: 'admin',
                password: 'admin321'
            },
            token2: {
                city: '北京',
                money: '1100w',
                sex: '女',
                userName: 'zhangsan',
                password: 'zs321'
            },
            token3: {
                city: '北京',
                money: '800w',
                sex: '男',
                userName: 'lisi',
                password: 'ls321'
            },
            token4: {
                city: '天津',
                money: '600w',
                sex: '男',
                userName: 'yyqx',
                password: 'yyqx321'
            }
        }
        function fn(a, b) {
            let conte = 0
            conte++
            if(conte===2) {
                return  alert('无机会,直接退出了')
            }
            for (; ;) {
                let unume = prompt('请输入用户名')
                let psw = prompt('请输入密码')
                
                for (let i = 0; i < a.length; i++) {
                    if (unume !== a[i].userName && psw !== a[i].password) {
                        if (conte > 1) {
                            alert('无机会,直接退出了')
                            break
                        }
                        let tiSi = +prompt(`账号不存在:
                         1. 注册 
                        2.直接退出`)
                        let unumeZuce = prompt('请输入用户名')
                        let pswZuce = prompt('请输入密码')
                        if (tiSi === 1) {
                            a.unshift({ userName: unumeZuce, password: pswZuce },)
                            alert('注册成功,去登录')
                            ++conte
                        }
                    } else {
                        for (let k in b) {
                            for (let key in b[k]) {
                                let tokenSui = Math.floor(Math.random() * 4) + 1
                                let token = `token${tokenSui}`
                                if (token === k) {
                                    delete b[k].password
                                    alert(`登录成功，用户信息具体为下：


                city: '${b[k].city}',
                money: '${b[k].money}',
                sex: '${b[k].sex}',
                userName: '${b[k].userName}',
            `)
            break

                                }
                                break
                            }
                        }
                    }
                    break

                }
            }

            return
        }
        fn(loginList, userInfo)
      
    </script>
</body>

</html>